from contextvars import ContextVar

request_id: ContextVar[str] = ContextVar("request_id", default="")


def singleton(cls):
  instances = {}

  def get_instance(*args, **kwargs):
    if cls not in instances:
      instances[cls] = cls(*args, **kwargs)
    return instances[cls]

  return get_instance
